#include "pinbase.h"
#include "global.h"

PinBase::PinBase(QObject *parent, int x, int y, unsigned int id, unsigned char datawidth)
{
	this->parent = parent;
	refWires = new QList<WireBase*>;
	pos.setX(x);
	pos.setY(y);
    this->id = id;
	this->datawidth = datawidth;
}

PinBase::~PinBase()
{
    for(int i=0; i<refWires->count(); i++)
    {
        if (refWires->at(i)->endPin == this)
            refWires->at(i)->endPin = NULL;
        if (refWires->at(i)->startPin == this)
            refWires->at(i)->startPin = NULL;
    }
    delete refWires;
}

void PinBase::addRefWire(WireBase *refWire)
{
	refWires->append(refWire);
}

void PinBase::removeRefWire(WireBase *refWire)
{
	refWires->removeOne(refWire);
}

bool PinBase::hasRefWire()
{
	return (refWires->count() > 0);
}

unsigned int PinBase::getRefCount()
{
	return refWires->count();
}

WireBase* PinBase::getRefWire(int idx)
{
    if (idx < refWires->count())
        return refWires->at(idx);
    else
        return NULL;
}

void PinBase::move(QPoint offset)
{
	this->pos = offset;
}

void PinBase::resetMemoryFlagIdx()
{
    this->memoryFlagIdx = NETIDX_NOT_CONNECTED;
}
